include Makefile.def


CFLAGS += -I./aliens/libharu-2.1.0/include -I./aliens/libharu-2.1.0/win32/include
CFLAGS += -I./aliens/excel
CFLAGS += -I./src 

ifeq ($(MODULES),yes)  
CFLAGS += -I./modules
#CFLAGS += -I/home/oracle/rdbms/public
CFLAGS +=  -I/usr/include/oracle/11.2/client64/
endif

LDFLAGS=

_default: all

################################ SRC PART #####################################
IMPOTANT_HEADER = \
	src/IGrid.h \
	src/IPhysicFormat.h \
	src/GridBase.h \
	
SRCS	= \
	src/Debug.cpp \
	src/Text.cpp \
	src/GridBase.cpp \
	src/PdfBase.cpp \
	src/PdfPage.cpp \
	src/PdfGrid.cpp \
	src/ExcelBase.cpp \
	
	
ifeq ($(MODULES),yes)  
SRCS += \
	modules/oracle/GridOci.cpp \
	modules/oracle/OciBase.cpp \

endif	
	
	
OBJS =  $(addprefix ${BUILD}/, $(SRCS:.cpp=.o))

${BUILD}/%.o: %.cpp %.h	$(IMPOTANT_HEADER)
	@$(MKDIR) ${BUILD}/src   ${BUILD}/modules/oracle/
	$(CXX) $(OPTS) $(CFLAGS) $(DLLFLAGS) -c ${COMPILIER_OUT}$@ $<


RC_SRCS = \
	src/report.rc \
	

RC_OBJS	=  $(addprefix ${BUILD}/, $(RC_SRCS:.rc=.rc_o))

ifeq ($(shell uname),Windows)                                                                                                          
	OBJS += $(RC_OBJS)
endif


${BUILD}/%.rc_o: %.rc
	$(RC) $< $@


###############################################################################


aliens.src: 
	$(MAKE) -f aliens/Makefile

utils.src: 
	$(CC) $(OPTS) ${COMPILIER_OUT}$(BUILD)/font2hex.exe utils/font2hex.c 


#http://www.adp-gmbh.ch/win/misc/mingw/dll.html 
$(BUILD)/fir.dll:  $(OBJS)
	$(AR) -rcs ${BUILD}/lib/libfir.a  $^
	$(CXX) -shared $(LDFLAGS) $^ \
	$(IMPFLAGS) \
	${COMPILIER_OUT} $(BUILD)/fir.dll \
	$(BUILD)/lib/aliens.a 

## linux
$(BUILD)/libfir.so.$(SO_VERSION):  $(OBJS)
	$(AR) -rcs ${BUILD}/lib/libfir.a $^
	$(CXX) -shared $(LDFLAGS) $^ \
	-Wl,-soname,libfir.so \
	${COMPILIER_OUT}$(BUILD)/libfir.so.$(SO_VERSION) \
	$(BUILD)/lib/aliens.a 	
	chmod 755 $(BUILD)/libfir.so.$(SO_VERSION) 
	cd $(BUILD); ln -s libfir.so.$(SO_VERSION) libfir.so; cd ..



$(BUILD)/libfir.dylib:  $(OBJS)
	$(AR) -rcs ${BUILD}/lib/libfir.a  $(OBJS)
	$(CXX) -shared $(LDFLAGS) $(OBJS) \
	$(IMPFLAGS) \
	${COMPILIER_OUT} $(BUILD)/libfir.dylib \
	$(BUILD)/lib/aliens.a 


#	cd $(BUILD); ln -s report.dll libreport.so; cd ..


tests.src: 
	$(MAKE) -f tests/Makefile

samples.src:
	$(MAKE) -f samples/Makefile


TARGET =  aliens.src

ifeq ($(shell uname),Linux)
TARGET += $(BUILD)/libfir.so.$(SO_VERSION)
endif

ifeq ($(shell uname),Darwin)
TARGET += $(BUILD)/libfir.dylib
endif

ifeq ($(shell uname),Windows)
TARGET += $(BUILD)/fir.dll
endif

TARGET += utils.src   samples.src
#TARGET +=tests.src

#change doxygen file version
doxygen:
	@cat Doxyfile |awk '{print gensub(/PROJECT_NUMBER =.*/,"PROJECT_NUMBER = <h2>Build</h2> "strftime("\\&nbsp;%a\\&nbsp;%b\\&nbsp;%d\\&nbsp;%H:%M\\&nbsp;%Y"),"G")}' >/tmp/Doxyfile.tmp && cp -f /tmp/Doxyfile.tmp Doxyfile  

TARGET += doxygen
	
all: $(TARGET)
	@echo " === make report for $(shell uname) === "
	
clean:
	@echo "clean report"
	$(RM) $(BUILD)/src/*.*
	$(RM) $(BUILD)/sample/*.*
	$(RM) $(BUILD)/lib/libfir.a
	$(RM) $(BUILD)/*.*